package team.sun.sss.controller.log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.sun.sss.dao.log.LogTalkDao;
import team.sun.sss.dao.staff.StaffDao;
import team.sun.sss.dao.student.StudentDao;

import java.util.List;
import java.util.Map;


@RestController
public class LogTalkController {

    @Autowired
    LogTalkDao logTalkDao;

    @Autowired
    StaffDao staffDao;

    @Autowired
    StudentDao studentDao;

    @GetMapping("/LogTalkList")
    public List<Map<String,Object>> LogTalkList(){
        List<Map<String,Object>> logTalkList=logTalkDao.getLogTalkList();
        return logTalkList;
    }
    @GetMapping("/LogStaTalkList/{log_sta}")
    public List<Map<String,Object>> LogStaTalkList(@PathVariable String log_sta){
        List<Map<String,Object>> LogStaTalkList=logTalkDao.getLogStaTalkList(log_sta);
        return LogStaTalkList;
    }

    @PostMapping("LogStaTalkListSelect")
    public List<Map<String,Object>> LogStaTalkListSelect(@RequestParam int userId,@RequestParam String stu_name, @RequestParam String stu_college,@RequestParam String stu_major){
        List<Map<String,Object>> LogStaTalkList = null;
        String log_sta = staffDao.getStaName(userId);
        if(stu_name == "" ){
            stu_name =null;
        }
        if(stu_college == "" ){
            stu_college =null;
        }
        if(stu_major == "" ){
            stu_major =null;
        }
        try {
            System.out.println(stu_name==null);
             LogStaTalkList=logTalkDao.getLogStaTalkListSelect(log_sta,stu_name,stu_college,stu_major);
        }catch (Exception e){
            System.out.println(e);
        }
        System.out.println("修改成功");
        return LogStaTalkList;
    }

    @GetMapping("/select_stu/{stu_id}")
    public List<Map<String,Object>> select_sut(@PathVariable int stu_id){
        List<Map<String,Object>> select_sut=studentDao.getUserList(stu_id);
        return select_sut;
    }

    @GetMapping("/LogTalkList/UserId/{UserId}")
    public List<Map<String,Object>> LogStaTalkListId(@PathVariable int UserId){
        String log_sta = staffDao.getStaName(UserId);
        List<Map<String,Object>> LogStaTalkList=logTalkDao.getLogStaTalkList(log_sta);
        return LogStaTalkList;
    }


    @GetMapping("/log_delete/{id}")
    public String log_delete(@PathVariable Integer id){
        try {
            logTalkDao.deleteLogTalk(id);
        }catch (Exception e){
            System.out.println("删除失败");
            return "删除失败";
        }
        System.out.println("删除成功");
        return "删除成功";
    }




}
